package com.qd.common.park.domain.commodity;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.cdqidi.dict.annotation.FieldBind;
import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.qd.common.dict.DictConstant;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 商品分类
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class CommodityClassificationDTO extends BaseQuery {

    @ExcelIgnore
    @JsonIgnore
    private static final String EXCEL_TITLE = "商品分类";
    /**
     * 主键
     */
    @ExcelProperty(value = {EXCEL_TITLE, "分类编码"})
    @NotBlank(message = "分类编码不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "分类编码长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String classificationCode;
    /**
     * 分类名称
     */
    @ExcelProperty(value = {EXCEL_TITLE,"分类名称"})
    @NotBlank(message = "分类名称不能为空", groups = DefaultGroup.class)
    @Size(max = 100, message = "分类名称长度不能超过{max}位", groups = DefaultGroup.class)
    private String classificationName;
    /**
     * 父级分类编码
     */
    @ExcelProperty(value = {EXCEL_TITLE,"父级分类编码"})
    @FieldBind(targetField = "parentCodeDisplay",processName = DictConstant.DC_COMMODITY_CLASSIFICATION)
    private String parentCode;
    /**
     * 父级分类编码显示
     */
    @ExcelProperty(value = {EXCEL_TITLE,"父级分类名称"})
    private String parentCodeDisplay;
    /**
     * 排序
     */
    @ExcelProperty(value = {EXCEL_TITLE,"排序"})
    private Integer idx;
    /**
     * 添加时间
     */
    @ExcelProperty(value = {EXCEL_TITLE,"添加时间"})
    private LocalDateTime addTime;
    /**
     * 修改时间
     */
    @ExcelProperty(value = {EXCEL_TITLE,"修改时间"})
    private LocalDateTime updateTime;
    /**
     * 操作人
     */
    @ExcelIgnore
    @FieldBind(targetField = "operatorDisplay",processName = DictConstant.SYS_LOGIN_USER)
    @Size(max = 50, message = "操作人长度不能超过{max}位", groups = DefaultGroup.class)
    private String operator;
    /**
     * 操作人显示
     */
    @ExcelProperty(value = {EXCEL_TITLE,"操作人"})
    private String operatorDisplay;
    /**
     * 机构ID
     */
    @ExcelIgnore
    @FieldBind(targetField = "orgIdDisplay",processName = DictConstant.SYS_ORG)
    @Size(max = 50, message = "机构ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String orgId;
    /**
     * 机构ID显示
     */
    @ExcelProperty(value = {EXCEL_TITLE,"操作人单位"})
    private String orgIdDisplay;
    /**
     * 子分类
     */
    @ExcelIgnore
    private List<CommodityClassificationDTO> children;

    @Override
    public void freeData() {
        this.classificationCode = null;
        this.classificationName = null;
        this.parentCode = null;
        this.parentCodeDisplay = null;
        this.addTime = null;
        this.updateTime = null;
        this.operator = null;
        this.operatorDisplay = null;
        this.orgId = null;
        this.orgIdDisplay = null;
        this.idx = null;
        Optional.ofNullable(children).ifPresent(List::clear);
        super.freeData();
    }
}
